//
//  NKCaseChoseVC.m
//  NewKY
//
//  Created by MXQ on 2016/11/14.
//  Copyright © 2016年 Dee. All rights reserved.
//

#import "NKCaseChoseVC.h"
#import "NKCaceChoseCell.h"

@interface NKCaseChoseVC ()<UITableViewDataSource,UITableViewDelegate>

//illTypeList
@property(nonatomic,strong)NSArray * illTypeList;

//tableView
@property(nonatomic,weak)UITableView * tableView;

@end

@implementation NKCaseChoseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (self.isTypeVC == YES) {
    
        _illTypeList = [NSArray arrayWithObjects:@"肿瘤病" ,@"血液病",@"心脑血管病",@"神经系统",@"骨科",nil];
        
    }
    else{

        NSLog(@"%zd",self.illtypeNum);

        NSDictionary * dict = @{
        
                                @"page":@1,
                                @"page_size":@15,
                                @"ci1_id":[NSString stringWithFormat:@"%zd",self.illtypeNum],
                                @"keyword":@""
        
        };
        
      [[NetWorkingManager shareManager]POST:@"http://iosapi.itcast.cn/doctor/searchCI3List.json.php" parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
          
          
          
          
          
      } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
          
          
          
          NSArray * arr = responseObject[@"data"];
          
          NSLog(@"%@",arr);
          
          NSMutableArray * arrm = [[NSMutableArray alloc]init];
          for (NSDictionary * dict in arr) {
              
              NSLog(@"%@",dict);
              
//              NSString * key = [NSString stringWithFormat:@"ci%zd_name",self.illtypeNum];
              NSString * key = @"ci3_name";
              
              [arrm appendObject:dict[key]];
              
              
          }
          
          
          self.illTypeList = arrm;
          
          [[NSOperationQueue mainQueue]addOperationWithBlock:^{
             
              [self.tableView reloadData];
              
          }];
          
          
          
          
          
          
          
      } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
          
          
      }];
        
        
        
    
    }
    // Do any additional setup after loading the view.

    UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    
    [tableView registerClass:[NKCaceChoseCell class] forCellReuseIdentifier:@"KAka"] ;
    
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
        
    }];
    
    
    tableView.dataSource =self;
    tableView.delegate = self;
    
    
    self.tableView = tableView;
    
}
// 实现数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableViewP{
    
    return  1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.illTypeList.count;
}

- (NKCaceChoseCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NKCaceChoseCell * cell = [tableView dequeueReusableCellWithIdentifier:@"KAka" forIndexPath:indexPath];
    
    cell.textLabel.text = self.illTypeList[indexPath.row];
    return cell;
    
}

//tableview代理方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.illTypeDidSelectBlock(_illTypeList[indexPath.row],indexPath.row+1);
    
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
